package s.k.gui.webtest.unittest;

import java.io.IOException;

import java.util.Iterator;
import java.util.Set;


import org.apache.http.client.ClientProtocolException;
import org.junit.Before;
import org.junit.Test;

import s.k.gui.webtest.page.resource.PageResource;


public class TestPageResource {
	PageResource pr;
	@Before
	public void setUp(){
		pr = new PageResource();
	}
	@Test
	public void testgetAllLinks(){
		Set<String> links = null;
		links = pr.getAllLinks("http://www.baidu.com");
		Iterator<String> iter =links.iterator();
		while(iter.hasNext()){
			String link =iter.next();			
			System.out.println(link);
		}
	}
	@Test
	public void testIsStatusOK(){
		boolean bool = pr.isStatusOK("http://www.baidu.com");
		System.out.println(bool);
	}

	@Test
	public void testgetResponse(){
		try {
			pr.getResponse("http://www.baidu.com");
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Test
	public void testdownLoadPageText(){
		pr.downloadPageText("http://www.baidu.com", "d:\\123.html");
		
	}
	@Test
	public void testgetHtmlByUrl(){
		pr.getHtmlByUrl("http://www.baidu.com");
	}
	@Test
	public void testCloseHttpClient(){
		pr.closeHttpClient();
	}
	@Test
	public void testIsExistText(){
		pr.isExistText("http://www.baidu.com", "<div id=\"u\"><a href=\"http://www.baidu.com/gaoji/preferences.html\" name=\"tj_setting\">");
	}
}